<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
    <head>
        <title>商品列表查询</title>
    </head>
    <body>
        <div class="container">
            <jsp:include page="../common.jsp"/>
            <table class="table table-striped">
                <thead>
                    <tr class="success">
                        <th></th>
                        <th>商品标识</th>
                        <th>商品名称</th>
                        <th>商品价格</th>
                        <th>商品评价</th>
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${goodslist}" var="goods">
                        <tr>
                            <td>
                                <input type="checkbox" value="${goods.id}" class="roleId"/>
                            </td>
                            <td>${goods.id}</td>
                            <td>${goods.name}</td>
                            <td>${goods.price}</td>
                            <td>${goods.remark}</td>
                            <td>
                                <a href="<%=request.getContextPath()%>/admin/role/update/${goods.id}">更新</a>
                                <a href="<%=request.getContextPath()%>/admin/role/resources/${goods.id}">设置资源</a>
                            </td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
            角色操作：<a class="btn btn-success" role="button" href="<%=request.getContextPath()%>/admin/role/add">添加角色</a>
            <a id="deleteRoleBtn" class="btn btn-success" role="button">删除角色</a>
        </div>

        <script type="text/javascript" src="<%=request.getContextPath()%>/resources/jquery-3.1.0.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#deleteRoleBtn").on("click",function(){
                    var checkedArray = [];
                    $("input[class='roleId']:checked").each(function () {
                        checkedArray.push($(this).val());
                    });
                    if(checkedArray.length == 0){
                        alert("请至少选择一个角色");
                    }
                    $.post("<%=request.getContextPath()%>/admin/role/delete",{
                        "roleIds":checkedArray
                    },function (data) {
                        if(data.success){
                            alert("删除用户成功!");
                            location.href="<%=request.getContextPath()%>/admin/role/list";

                        }
                    });
                });
            });

        </script>
    </body>
</html>
